library(ri)
library(ggplot2)
library(fastDummies)
library(AER)
library(gridExtra)
library(ri2)

setwd("")

##Set number of simulations for code
N <- 100000

data <- read.csv("Who is the Party - data cleaned for replication archive.csv", na.strings = c("", "NA"))

data <- data[which(data$block != 0),]

data$attentive <- (1 - data$inattentive)

data$attentive[which(data$condition == 3)] <- 0
data$attentive[which(data$condition == 6)] <- 0

#data <- data[which(data$pid7 != 4),]
#Adding in dummies for blocks before splitting the dataset up by condition

data <- dummy_cols(data, select_columns = c("block"))
data <- dummy_cols(data, select_columns = c("pid7"))

#Creating indicator variables for each pair of conditions

data$conditionOneTwo <- NA
data$conditionOneTwo[which(data$condition == 1)] <- 1
data$conditionOneTwo[which(data$condition == 2)] <- 0

data$conditionOneThree <- NA
data$conditionOneThree[which(data$condition == 1)] <- 1
data$conditionOneThree[which(data$condition == 3)] <- 0

data$conditionTwoThree <- NA
data$conditionTwoThree[which(data$condition == 2)] <- 1
data$conditionTwoThree[which(data$condition == 3)] <- 0

data$conditionFourFive <- NA
data$conditionFourFive[which(data$condition == 4)] <- 1
data$conditionFourFive[which(data$condition == 5)] <- 0

data$conditionFourSix <- NA
data$conditionFourSix[which(data$condition == 4)] <- 1
data$conditionFourSix[which(data$condition == 6)] <- 0

data$conditionFiveSix <- NA
data$conditionFiveSix[which(data$condition == 5)] <- 1
data$conditionFiveSix[which(data$condition == 6)] <- 0

##First testing H1, about perceived Ideology of out-party

#Dems' views of Reps

#General Ideology

set.seed(203210)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repIdeo) == F & data$inattentive == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repIdeo <- estate(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repIdeoOuts <- genouts(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo)

repIdeoDist <- gendist(repIdeoOuts, perms = perms, prob = probsOneTwo)

repIdeoCI <- c(invert.ci(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

repIdeoD <- repIdeo/sd(dataOneTwo$repIdeo, na.rm = T)

#For Appendix B, comparing high and low-interest respondents

set.seed(382081)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repIdeo) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repIdeo_hiInt <- estate(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repIdeoOuts_hiInt <- genouts(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo)

repIdeoDist_hiInt <- gendist(repIdeoOuts_hiInt, perms = perms, prob = probsOneTwo)

repIdeoCI_hiInt <- c(invert.ci(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repIdeoDist_hiInt, repIdeo_hiInt)

repIdeoD_hiInt <- repIdeo_hiInt/sd(dataOneTwo$repIdeo)

set.seed(221230)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repIdeo) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repIdeo_loInt <- estate(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repIdeoOuts_loInt <- genouts(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo)

repIdeoDist_loInt <- gendist(repIdeoOuts_loInt, perms = perms, prob = probsOneTwo)

repIdeoCI_loInt <- c(invert.ci(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repIdeo, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repIdeoDist_loInt, repIdeo_loInt)

repIdeoD_loInt <- repIdeo_loInt/sd(dataOneTwo$repIdeo)

#F-test to check for HTE by interest

set.seed(71473)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repIdeo) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataOneTwo$block)

repIdeoHTE <- conduct_ri(
  model_1 = repIdeo ~ conditionOneTwo + interest,
  model_2 = repIdeo ~ conditionOneTwo + interest + conditionOneTwo*interest,
  declaration = declaration,
  sharp_hypothesis = repIdeo,
  assignment = "conditionOneTwo",
  data = dataOneTwo,
  sims = N
)

#Taxes

set.seed(384235)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repTaxes) == F & data$inattentive == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repTaxes <- estate(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repTaxesOuts <- genouts(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo)

repTaxesDist <- gendist(repTaxesOuts, perms = perms, prob = probsOneTwo)

repTaxesCI <- c(invert.ci(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repTaxesDist, repTaxes)

repTaxesD <- repTaxes/sd(dataOneTwo$repTaxes)

#For Appendix B, comparing high and low-interest respondents

set.seed(751954)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repTaxes) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repTaxes_hiInt <- estate(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repTaxesOuts_hiInt <- genouts(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo)

repTaxesDist_hiInt <- gendist(repTaxesOuts_hiInt, perms = perms, prob = probsOneTwo)

repTaxesCI_hiInt <- c(invert.ci(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repTaxesDist_hiInt, repTaxes_hiInt)

repTaxesD_hiInt <- repTaxes_hiInt/sd(dataOneTwo$repTaxes)

set.seed(989347)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repTaxes) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repTaxes_loInt <- estate(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repTaxesOuts_loInt <- genouts(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo)

repTaxesDist_loInt <- gendist(repTaxesOuts_loInt, perms = perms, prob = probsOneTwo)

repTaxesCI_loInt <- c(invert.ci(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repTaxes, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repTaxesDist_loInt, repTaxes_loInt)

repTaxesD_loInt <- repTaxes_loInt/sd(dataOneTwo$repTaxes)

#F-test to check for HTE by interest

set.seed(104040)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repTaxes) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataOneTwo$block)

repTaxesHTE <- conduct_ri(
  model_1 = repTaxes ~ conditionOneTwo + interest,
  model_2 = repTaxes ~ conditionOneTwo + interest + conditionOneTwo*interest,
  declaration = declaration,
  sharp_hypothesis = repTaxes,
  assignment = "conditionOneTwo",
  data = dataOneTwo,
  sims = N
)

#Immigration

set.seed(273279)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repImmig) == F & data$inattentive == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repImmig <- estate(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repImmigOuts <- genouts(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo)

repImmigDist <- gendist(repImmigOuts, perms = perms, prob = probsOneTwo)

repImmigCI <- c(invert.ci(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repImmigDist, repImmig)

repImmigD <- repImmig/sd(dataOneTwo$repImmig)

#For Appendix B, comparing high and low-interest respondents

set.seed(727080)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repImmig) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)
repImmig_hiInt <- estate(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repImmigOuts_hiInt <- genouts(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo)

repImmigDist_hiInt <- gendist(repImmigOuts_hiInt, perms = perms, prob = probsOneTwo)

repImmigCI_hiInt <- c(invert.ci(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repImmigDist_hiInt, repImmig_hiInt)

repImmigD_hiInt <- repImmig_hiInt/sd(dataOneTwo$repImmig)

set.seed(753673)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repImmig) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repImmig_loInt <- estate(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repImmigOuts_loInt <- genouts(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo)

repImmigDist_loInt <- gendist(repImmigOuts_loInt, perms = perms, prob = probsOneTwo)

repImmigCI_loInt <- c(invert.ci(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repImmig, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repImmigDist_loInt, repImmig_loInt)

repImmigD_loInt <- repImmig_loInt/sd(dataOneTwo$repImmig)

#F-test to check for HTE by interest

set.seed(44899)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repImmig) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataOneTwo$block)

repImmigHTE <- conduct_ri(
  model_1 = repImmig ~ conditionOneTwo + interest,
  model_2 = repImmig ~ conditionOneTwo + interest + conditionOneTwo*interest,
  declaration = declaration,
  sharp_hypothesis = repImmig,
  assignment = "conditionOneTwo",
  data = dataOneTwo,
  sims = N
)

#Abortion

set.seed(595260)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repAbortion) == F & data$inattentive == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repAbortion <- estate(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repAbortionOuts <- genouts(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo)

repAbortionDist <- gendist(repAbortionOuts, perms = perms, prob = probsOneTwo)

repAbortionCI <- c(invert.ci(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repAbortionDist, repAbortion)

repAbortionD <- repAbortion/sd(dataOneTwo$repAbortion)

#For Appendix B, comparing high and low-interest respondents

set.seed(711201)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repAbortion) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repAbortion_hiInt <- estate(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repAbortionOuts_hiInt <- genouts(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo)

repAbortionDist_hiInt <- gendist(repAbortionOuts_hiInt, perms = perms, prob = probsOneTwo)

repAbortionCI_hiInt <- c(invert.ci(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repAbortionDist_hiInt, repAbortion_hiInt)

repAbortionD_hiInt <- repAbortion_hiInt/sd(dataOneTwo$repAbortion)

set.seed(658314)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repAbortion) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repAbortion_loInt <- estate(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repAbortionOuts_loInt <- genouts(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo)

repAbortionDist_loInt <- gendist(repAbortionOuts_loInt, perms = perms, prob = probsOneTwo)

repAbortionCI_loInt <- c(invert.ci(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repAbortion, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repAbortionDist_loInt, repAbortion_loInt)

repAbortionD_loInt <- repAbortion_loInt/sd(dataOneTwo$repAbortion)

#F-test to check for HTE by interest

set.seed(748104)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repAbortion) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataOneTwo$block)

repAbortionHTE <- conduct_ri(
  model_1 = repAbortion ~ conditionOneTwo + interest,
  model_2 = repAbortion ~ conditionOneTwo + interest + conditionOneTwo*interest,
  declaration = declaration,
  sharp_hypothesis = repAbortion,
  assignment = "conditionOneTwo",
  data = dataOneTwo,
  sims = N
)

#Now an analysis of the index created from these three issues. 
#Note that since the reliability of this index was below 0.7, this is not the pre-registered analysis.

set.seed(51031)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repIssueIndex) == F & data$inattentive == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repIssueIndex <- estate(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repIssueIndexOuts <- genouts(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo)

repIssueIndexDist <- gendist(repIssueIndexOuts, perms = perms, prob = probsOneTwo)

repIssueIndexCI <- c(invert.ci(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repIssueIndexDist, repIssueIndex)

repIssueIndexD <- repIssueIndex/sd(dataOneTwo$repIssueIndex)

#For Appendix B, comparing high and low-interest respondents

set.seed(215725)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repIssueIndex) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repIssueIndex_hiInt <- estate(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repIssueIndexOuts_hiInt <- genouts(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo)

repIssueIndexDist_hiInt <- gendist(repIssueIndexOuts_hiInt, perms = perms, prob = probsOneTwo)

repIssueIndexCI_hiInt <- c(invert.ci(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repIssueIndexDist_hiInt, repIssueIndex_hiInt)

repIssueIndexD_hiInt <- repIssueIndex_hiInt/sd(dataOneTwo$repIssueIndex)

set.seed(529370)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repIssueIndex) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repIssueIndex_loInt <- estate(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repIssueIndexOuts_loInt <- genouts(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo)

repIssueIndexDist_loInt <- gendist(repIssueIndexOuts_loInt, perms = perms, prob = probsOneTwo)

repIssueIndexCI_loInt <- c(invert.ci(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repIssueIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repIssueIndexDist_loInt, repIssueIndex_loInt)

repIssueIndexD_loInt <- repIssueIndex_loInt/sd(dataOneTwo$repIssueIndex)

#F-test to check for HTE by interest

set.seed(88554)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repIssueIndex) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataOneTwo$block)

repIssueIndexHTE <- conduct_ri(
  model_1 = repIssueIndex ~ conditionOneTwo + interest,
  model_2 = repIssueIndex ~ conditionOneTwo + interest + conditionOneTwo*interest,
  declaration = declaration,
  sharp_hypothesis = repIssueIndex,
  assignment = "conditionOneTwo",
  data = dataOneTwo,
  sims = N
)


#Reps' views of Dems

#General ideology

set.seed(55249)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demIdeo) == F & data$inattentive == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demIdeo <- estate(dataFourFive$demIdeo, dataFourFive$conditionFourFive, prob = probsFourFive)

demIdeoOuts <- genouts(dataFourFive$demIdeo, dataFourFive$conditionFourFive)

demIdeoDist <- gendist(demIdeoOuts, perms = perms, prob = probsFourFive)

demIdeoCI <- c(invert.ci(dataFourFive$demIdeo, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demIdeo, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demIdeoDist, demIdeo)

demIdeoD <- demIdeo/sd(dataFourFive$demIdeo)

#For Appendix B, comparing high and low-interest respondents

set.seed(382081)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demIdeo) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demIdeo_hiInt <- estate(dataFourFive$demIdeo, dataFourFive$conditionFourFive, prob = probsFourFive)

demIdeoOuts_hiInt <- genouts(dataFourFive$demIdeo, dataFourFive$conditionFourFive)

demIdeoDist_hiInt <- gendist(demIdeoOuts_hiInt, perms = perms, prob = probsFourFive)

demIdeoCI_hiInt <- c(invert.ci(dataFourFive$demIdeo, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demIdeo, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demIdeoDist_hiInt, demIdeo_hiInt)

demIdeoD_hiInt <- demIdeo_hiInt/sd(dataFourFive$demIdeo)

set.seed(289798)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demIdeo) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demIdeo_loInt <- estate(dataFourFive$demIdeo, dataFourFive$conditionFourFive, prob = probsFourFive)

demIdeoOuts_loInt <- genouts(dataFourFive$demIdeo, dataFourFive$conditionFourFive)

demIdeoDist_loInt <- gendist(demIdeoOuts_loInt, perms = perms, prob = probsFourFive)

demIdeoCI_loInt <- c(invert.ci(dataFourFive$demIdeo, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demIdeo, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demIdeoDist_loInt, demIdeo_loInt)

demIdeoD_loInt <- demIdeo_loInt/sd(dataFourFive$demIdeo)

#F-test to check for HTE by interest

set.seed(182943)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demIdeo) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataFourFive$block)

demIdeoHTE <- conduct_ri(
  model_1 = demIdeo ~ conditionFourFive + interest,
  model_2 = demIdeo ~ conditionFourFive + interest + conditionFourFive*interest,
  declaration = declaration,
  sharp_hypothesis = demIdeo,
  assignment = "conditionFourFive",
  data = dataFourFive,
  sims = N
)

#Taxes

set.seed(105396)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demTaxes) == F & data$inattentive == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demTaxes <- estate(dataFourFive$demTaxes, dataFourFive$conditionFourFive, prob = probsFourFive)

demTaxesOuts <- genouts(dataFourFive$demTaxes, dataFourFive$conditionFourFive)

demTaxesDist <- gendist(demTaxesOuts, perms = perms, prob = probsFourFive)

demTaxesCI <- c(invert.ci(dataFourFive$demTaxes, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demTaxes, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demTaxesDist, demTaxes)

demTaxesD <- demTaxes/sd(dataFourFive$demTaxes)

#For Appendix B, comparing high and low-interest respondents

set.seed(4586)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demTaxes) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demTaxes_hiInt <- estate(dataFourFive$demTaxes, dataFourFive$conditionFourFive, prob = probsFourFive)

demTaxesOuts_hiInt <- genouts(dataFourFive$demTaxes, dataFourFive$conditionFourFive)

demTaxesDist_hiInt <- gendist(demTaxesOuts_hiInt, perms = perms, prob = probsFourFive)

demTaxesCI_hiInt <- c(invert.ci(dataFourFive$demTaxes, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demTaxes, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demTaxesDist_hiInt, demTaxes_hiInt)

demTaxesD_hiInt <- demTaxes_hiInt/sd(dataFourFive$demTaxes)

set.seed(743044)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demTaxes) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demTaxes_loInt <- estate(dataFourFive$demTaxes, dataFourFive$conditionFourFive, prob = probsFourFive)

demTaxesOuts_loInt <- genouts(dataFourFive$demTaxes, dataFourFive$conditionFourFive)

demTaxesDist_loInt <- gendist(demTaxesOuts_loInt, perms = perms, prob = probsFourFive)

demTaxesCI_loInt <- c(invert.ci(dataFourFive$demTaxes, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demTaxes, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demTaxesDist_loInt, demTaxes_loInt)

demTaxesD_loInt <- demTaxes_loInt/sd(dataFourFive$demTaxes)

#F-test to check for HTE by interest

set.seed(376394)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demTaxes) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataFourFive$block)

demTaxesHTE <- conduct_ri(
  model_1 = demTaxes ~ conditionFourFive + interest,
  model_2 = demTaxes ~ conditionFourFive + interest + conditionFourFive*interest,
  declaration = declaration,
  sharp_hypothesis = demTaxes,
  assignment = "conditionFourFive",
  data = dataFourFive,
  sims = N
)

#Immigration

set.seed(771606)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demImmig) == F & data$inattentive == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demImmig <- estate(dataFourFive$demImmig, dataFourFive$conditionFourFive, prob = probsFourFive)

demImmigOuts <- genouts(dataFourFive$demImmig, dataFourFive$conditionFourFive)

demImmigDist <- gendist(demImmigOuts, perms = perms, prob = probsFourFive)

demImmigCI <- c(invert.ci(dataFourFive$demImmig, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demImmig, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demImmigDist, demImmig)

demImmigD <- demImmig/sd(dataFourFive$demImmig)

#For Appendix B, comparing high and low-interest respondents

set.seed(925931)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demImmig) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)
demImmig_hiInt <- estate(dataFourFive$demImmig, dataFourFive$conditionFourFive, prob = probsFourFive)

demImmigOuts_hiInt <- genouts(dataFourFive$demImmig, dataFourFive$conditionFourFive)

demImmigDist_hiInt <- gendist(demImmigOuts_hiInt, perms = perms, prob = probsFourFive)

demImmigCI_hiInt <- c(invert.ci(dataFourFive$demImmig, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demImmig, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demImmigDist_hiInt, demImmig_hiInt)

demImmigD_hiInt <- demImmig_hiInt/sd(dataFourFive$demImmig)

set.seed(652558)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demImmig) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demImmig_loInt <- estate(dataFourFive$demImmig, dataFourFive$conditionFourFive, prob = probsFourFive)

demImmigOuts_loInt <- genouts(dataFourFive$demImmig, dataFourFive$conditionFourFive)

demImmigDist_loInt <- gendist(demImmigOuts_loInt, perms = perms, prob = probsFourFive)

demImmigCI_loInt <- c(invert.ci(dataFourFive$demImmig, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demImmig, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demImmigDist_loInt, demImmig_loInt)

demImmigD_loInt <- demImmig_loInt/sd(dataFourFive$demImmig)

#F-test to check for HTE by interest

set.seed(457657)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demImmig) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataFourFive$block)

demImmigHTE <- conduct_ri(
  model_1 = demImmig ~ conditionFourFive + interest,
  model_2 = demImmig ~ conditionFourFive + interest + conditionFourFive*interest,
  declaration = declaration,
  sharp_hypothesis = demImmig,
  assignment = "conditionFourFive",
  data = dataFourFive,
  sims = N
)

#Abortion

set.seed(70111)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demAbortion) == F & data$inattentive == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demAbortion <- estate(dataFourFive$demAbortion, dataFourFive$conditionFourFive, prob = probsFourFive)

demAbortionOuts <- genouts(dataFourFive$demAbortion, dataFourFive$conditionFourFive)

demAbortionDist <- gendist(demAbortionOuts, perms = perms, prob = probsFourFive)

demAbortionCI <- c(invert.ci(dataFourFive$demAbortion, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demAbortion, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demAbortionDist, demAbortion)

demAbortionD <- demAbortion/sd(dataFourFive$demAbortion)

#For Appendix B, comparing high and low-interest respondents

set.seed(610959)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demAbortion) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demAbortion_hiInt <- estate(dataFourFive$demAbortion, dataFourFive$conditionFourFive, prob = probsFourFive)

demAbortionOuts_hiInt <- genouts(dataFourFive$demAbortion, dataFourFive$conditionFourFive)

demAbortionDist_hiInt <- gendist(demAbortionOuts_hiInt, perms = perms, prob = probsFourFive)

demAbortionCI_hiInt <- c(invert.ci(dataFourFive$demAbortion, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demAbortion, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demAbortionDist_hiInt, demAbortion_hiInt)

demAbortionD_hiInt <- demAbortion_hiInt/sd(dataFourFive$demAbortion)

set.seed(139590)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demAbortion) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demAbortion_loInt <- estate(dataFourFive$demAbortion, dataFourFive$conditionFourFive, prob = probsFourFive)

demAbortionOuts_loInt <- genouts(dataFourFive$demAbortion, dataFourFive$conditionFourFive)

demAbortionDist_loInt <- gendist(demAbortionOuts_loInt, perms = perms, prob = probsFourFive)

demAbortionCI_loInt <- c(invert.ci(dataFourFive$demAbortion, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demAbortion, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demAbortionDist_loInt, demAbortion_loInt)

demAbortionD_loInt <- demAbortion_loInt/sd(dataFourFive$demAbortion)

#F-test to check for HTE by interest

set.seed(233121)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demAbortion) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataFourFive$block)

demAbortionHTE <- conduct_ri(
  model_1 = demAbortion ~ conditionFourFive + interest,
  model_2 = demAbortion ~ conditionFourFive + interest + conditionFourFive*interest,
  declaration = declaration,
  sharp_hypothesis = demAbortion,
  assignment = "conditionFourFive",
  data = dataFourFive,
  sims = N
)

#Now an analysis of the index created from these three issues. 
#Note that since the reliability of the issue index was below 0.7, this is not the pre-registered analysis.

set.seed(158970)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demIssueIndex) == F & data$inattentive == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demIssueIndex <- estate(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive, prob = probsFourFive)

demIssueIndexOuts <- genouts(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive)

demIssueIndexDist <- gendist(demIssueIndexOuts, perms = perms, prob = probsFourFive)

demIssueIndexCI <- c(invert.ci(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demIssueIndexDist, demIssueIndex)

demIssueIndexD <- demIssueIndex/sd(dataFourFive$demIssueIndex)

#For Appendix B, comparing high and low-interest respondents

set.seed(704716)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demIssueIndex) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demIssueIndex_hiInt <- estate(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive, prob = probsFourFive)

demIssueIndexOuts_hiInt <- genouts(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive)

demIssueIndexDist_hiInt <- gendist(demIssueIndexOuts_hiInt, perms = perms, prob = probsFourFive)

demIssueIndexCI_hiInt <- c(invert.ci(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demIssueIndexDist_hiInt, demIssueIndex_hiInt)

demIssueIndexD_hiInt <- demIssueIndex_hiInt/sd(dataFourFive$demIssueIndex)

set.seed(500571)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demIssueIndex) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demIssueIndex_loInt <- estate(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive, prob = probsFourFive)

demIssueIndexOuts_loInt <- genouts(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive)

demIssueIndexDist_loInt <- gendist(demIssueIndexOuts_loInt, perms = perms, prob = probsFourFive)

demIssueIndexCI_loInt <- c(invert.ci(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demIssueIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demIssueIndexDist_loInt, demIssueIndex_loInt)

demIssueIndexD_loInt <- demIssueIndex_loInt/sd(dataFourFive$demIssueIndex)

#F-test to check for HTE by interest

set.seed(113252)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demIssueIndex) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataFourFive$block)

demIssueIndexHTE <- conduct_ri(
  model_1 = demIssueIndex ~ conditionFourFive + interest,
  model_2 = demIssueIndex ~ conditionFourFive + interest + conditionFourFive*interest,
  declaration = declaration,
  sharp_hypothesis = demIssueIndex,
  assignment = "conditionFourFive",
  data = dataFourFive,
  sims = N
)

#Now testing H2, the out-group affect hypothesis

#Dem Affect towards Reps

#Affect Index

set.seed(53968)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repAffectIndex) == F & data$inattentive == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repAffectIndex <- estate(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repAffectIndexOuts <- genouts(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo)

repAffectIndexDist <- gendist(repAffectIndexOuts, perms = perms, prob = probsOneTwo)

repAffectIndexCI <- c(invert.ci(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repAffectIndexDist, repAffectIndex)

repAffectIndexD <- repAffectIndex/sd(dataOneTwo$repAffectIndex)

#For Appendix B, comparing high and low-interest respondents

set.seed(637733)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repAffectIndex) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repAffectIndex_hiInt <- estate(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repAffectIndexOuts_hiInt <- genouts(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo)

repAffectIndexDist_hiInt <- gendist(repAffectIndexOuts_hiInt, perms = perms, prob = probsOneTwo)

repAffectIndexCI_hiInt <- c(invert.ci(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repAffectIndexDist_hiInt, repAffectIndex_hiInt)

repAffectIndexD_hiInt <- repAffectIndex_hiInt/sd(dataOneTwo$repAffectIndex)

set.seed(62485)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repAffectIndex) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repAffectIndex_loInt <- estate(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repAffectIndexOuts_loInt <- genouts(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo)

repAffectIndexDist_loInt <- gendist(repAffectIndexOuts_loInt, perms = perms, prob = probsOneTwo)

repAffectIndexCI_loInt <- c(invert.ci(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repAffectIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repAffectIndexDist_loInt, repAffectIndex_loInt)

repAffectIndexD_loInt <- repAffectIndex_loInt/sd(dataOneTwo$repAffectIndex)

#F-test to check for HTE by interest

set.seed(588924)

dataOneTwo<- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repAffectIndex) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataOneTwo$block)

repAffectIndexHTE <- conduct_ri(
  model_1 = repAffectIndex ~ conditionOneTwo+ interest,
  model_2 = repAffectIndex ~ conditionOneTwo+ interest + conditionOneTwo*interest,
  declaration = declaration,
  sharp_hypothesis = repAffectIndex,
  assignment = "conditionOneTwo",
  data = dataOneTwo,
  sims = N
)

#Now an analysis of the two items making up this index.
#Note that since the reliability of the affect index was above 0.7, this is not the pre-registered analysis.

#Trust Index

set.seed(7690)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repTrustIndexRescale) == F & data$inattentive == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repTrustIndex <- estate(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repTrustIndexOuts <- genouts(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo)

repTrustIndexDist <- gendist(repTrustIndexOuts, perms = perms, prob = probsOneTwo)

repTrustIndexCI <- c(invert.ci(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repTrustIndexDist, repTrustIndex)

repTrustIndexD <- repTrustIndex/sd(dataOneTwo$repTrustIndex)

#For Appendix B, comparing high and low-interest respondents

set.seed(738181)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repTrustIndexRescale) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repTrustIndex_hiInt <- estate(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repTrustIndexOuts_hiInt <- genouts(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo)

repTrustIndexDist_hiInt <- gendist(repTrustIndexOuts_hiInt, perms = perms, prob = probsOneTwo)

repTrustIndexCI_hiInt <- c(invert.ci(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repTrustIndexDist_hiInt, repTrustIndex_hiInt)

repTrustIndexD_hiInt <- repTrustIndex_hiInt/sd(dataOneTwo$repTrustIndex)

set.seed(792764)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repTrustIndexRescale) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repTrustIndex_loInt <- estate(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repTrustIndexOuts_loInt <- genouts(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo)

repTrustIndexDist_loInt <- gendist(repTrustIndexOuts_loInt, perms = perms, prob = probsOneTwo)

repTrustIndexCI_loInt <- c(invert.ci(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repTrustIndexRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repTrustIndexDist_loInt, repTrustIndex_loInt)

repTrustIndexD_loInt <- repTrustIndex_loInt/sd(dataOneTwo$repTrustIndex)

#F-test to check for HTE by interest

set.seed(77830)

dataOneTwo<- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repTrustIndexRescale) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataOneTwo$block)

repTrustIndexHTE <- conduct_ri(
  model_1 = repTrustIndexRescale ~ conditionOneTwo+ interest,
  model_2 = repTrustIndexRescale ~ conditionOneTwo+ interest + conditionOneTwo*interest,
  declaration = declaration,
  sharp_hypothesis = repTrustIndex,
  assignment = "conditionOneTwo",
  data = dataOneTwo,
  sims = N
)

#Normalized Feeling Thermometer

set.seed(524673)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repThermNormRescale) == F & data$inattentive == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repThermNorm <- estate(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repThermNormOuts <- genouts(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo)

repThermNormDist <- gendist(repThermNormOuts, perms = perms, prob = probsOneTwo)

repThermNormCI <- c(invert.ci(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repThermNormDist, repThermNorm)

repThermNormD <- repThermNorm/sd(dataOneTwo$repThermNormRescale)

#For Appendix B, comparing high and low-interest respondents

set.seed(277277)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repThermNormRescale) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repThermNorm_hiInt <- estate(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repThermNormOuts_hiInt <- genouts(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo)

repThermNormDist_hiInt <- gendist(repThermNormOuts_hiInt, perms = perms, prob = probsOneTwo)

repThermNormCI_hiInt <- c(invert.ci(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repThermNormDist_hiInt, repThermNorm_hiInt)

repThermNormD_hiInt <- repThermNorm_hiInt/sd(dataOneTwo$repThermNorm)

set.seed(127188)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repThermNormRescale) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repThermNorm_loInt <- estate(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repThermNormOuts_loInt <- genouts(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo)

repThermNormDist_loInt <- gendist(repThermNormOuts_loInt, perms = perms, prob = probsOneTwo)

repThermNormCI_loInt <- c(invert.ci(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$repThermNormRescale, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repThermNormDist_loInt, repThermNorm_loInt)

repThermNormD_loInt <- repThermNorm_loInt/sd(dataOneTwo$repThermNorm)

#F-test to check for HTE by interest

set.seed(487910)

dataOneTwo<- data[which(is.na(data$conditionOneTwo) == F & is.na(data$repThermNormRescale) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataOneTwo$block)

repThermNormHTE <- conduct_ri(
  model_1 = repThermNormRescale ~ conditionOneTwo+ interest,
  model_2 = repThermNormRescale ~ conditionOneTwo+ interest + conditionOneTwo*interest,
  declaration = declaration,
  sharp_hypothesis = repThermNorm,
  assignment = "conditionOneTwo",
  data = dataOneTwo,
  sims = N
)

#Now Dem preferences for social distance to Reps

set.seed(845490)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$socDistRepsIndex) == F & data$inattentive == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repSocDistIndex <- estate(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repSocDistIndexOuts <- genouts(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo)

repSocDistIndexDist <- gendist(repSocDistIndexOuts, perms = perms, prob = probsOneTwo)

repSocDistIndexCI <- c(invert.ci(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repSocDistIndexDist, repSocDistIndex)

repSocDistIndexD <- repSocDistIndex/sd(dataOneTwo$socDistRepsIndex)

set.seed(171704)

#For Appendix B, comparing high and low-interest respondents

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$socDistRepsIndex) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repSocDistIndex_hiInt <- estate(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repSocDistIndexOuts_hiInt <- genouts(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo)

repSocDistIndexDist_hiInt <- gendist(repSocDistIndexOuts_hiInt, perms = perms, prob = probsOneTwo)

repSocDistIndexCI_hiInt <- c(invert.ci(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repSocDistIndexDist_hiInt, repSocDistIndex_hiInt)

repSocDistIndexD_hiInt <- repSocDistIndex_hiInt/sd(dataOneTwo$repSocDistIndex)

set.seed(318356)

dataOneTwo <- data[which(is.na(data$conditionOneTwo) == F & is.na(data$socDistRepsIndex) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block, maxiter = N)

probsOneTwo <- genprobexact(dataOneTwo$conditionOneTwo, blockvar = dataOneTwo$block)

repSocDistIndex_loInt <- estate(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo)

repSocDistIndexOuts_loInt <- genouts(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo)

repSocDistIndexDist_loInt <- gendist(repSocDistIndexOuts_loInt, perms = perms, prob = probsOneTwo)

repSocDistIndexCI_loInt <- c(invert.ci(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .05), invert.ci(dataOneTwo$socDistRepsIndex, dataOneTwo$conditionOneTwo, prob = probsOneTwo, perms = perms, targetp = .95))

dispdist(repSocDistIndexDist_loInt, repSocDistIndex_loInt)

repSocDistIndexD_loInt <- repSocDistIndex_loInt/sd(dataOneTwo$repSocDistIndex)

#F-test to check for HTE by interest

set.seed(410694)

dataOneTwo<- data[which(is.na(data$conditionOneTwo) == F & is.na(data$socDistRepsIndex) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataOneTwo$block)

repSocDistIndexHTE <- conduct_ri(
  model_1 = socDistRepsIndex ~ conditionOneTwo+ interest,
  model_2 = socDistRepsIndex ~ conditionOneTwo+ interest + conditionOneTwo*interest,
  declaration = declaration,
  sharp_hypothesis = repSocDistIndex,
  assignment = "conditionOneTwo",
  data = dataOneTwo,
  sims = N
)

#Rep affect towards Dems


set.seed(392716)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demAffectIndex) == F & data$inattentive == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demAffectIndex <- estate(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive, prob = probsFourFive)

demAffectIndexOuts <- genouts(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive)

demAffectIndexDist <- gendist(demAffectIndexOuts, perms = perms, prob = probsFourFive)

demAffectIndexCI <- c(invert.ci(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demAffectIndexDist, demAffectIndex)

demAffectIndexD <- demAffectIndex/sd(dataOneTwo$demAffectIndex, na.rm = T)

set.seed(477401)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demAffectIndex) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demAffectIndex_hiInt <- estate(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive, prob = probsFourFive)

demAffectIndexOuts_hiInt <- genouts(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive)

demAffectIndexDist_hiInt <- gendist(demAffectIndexOuts_hiInt, perms = perms, prob = probsFourFive)

demAffectIndexCI_hiInt <- c(invert.ci(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demAffectIndexDist_hiInt, demAffectIndex_hiInt)

demAffectIndexD_hiInt <- demAffectIndex_hiInt/sd(dataOneTwo$demAffectIndex)

set.seed(278116)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demAffectIndex) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)


probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demAffectIndex_loInt <- estate(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive, prob = probsFourFive)

demAffectIndexOuts_loInt <- genouts(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive)

demAffectIndexDist_loInt <- gendist(demAffectIndexOuts_loInt, perms = perms, prob = probsFourFive)

demAffectIndexCI_loInt <- c(invert.ci(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demAffectIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demAffectIndexDist_loInt, demAffectIndex_loInt)

demAffectIndexD_loInt <- demAffectIndex_loInt/sd(dataOneTwo$demAffectIndex)

#Code to check for HTE by interest

set.seed(207072)

dataFourFive<- data[which(is.na(data$conditionFourFive) == F & is.na(data$demAffectIndex) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataFourFive$block)

demAffectIndexHTE <- conduct_ri(
  model_1 = demAffectIndex ~ conditionFourFive+ interest,
  model_2 = demAffectIndex ~ conditionFourFive+ interest + conditionFourFive*interest,
  declaration = declaration,
  sharp_hypothesis = demAffectIndex,
  assignment = "conditionFourFive",
  data = dataFourFive,
  sims = N
)

#Now an analysis of the two items making up this index.
#Note that since the reliability of the affect index was above 0.7, this is not the pre-registered analysis.

set.seed(463010)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demTrustIndexRescale) == F & data$inattentive == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demTrustIndex <- estate(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive, prob = probsFourFive)

demTrustIndexOuts <- genouts(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive)

demTrustIndexDist <- gendist(demTrustIndexOuts, perms = perms, prob = probsFourFive)

demTrustIndexCI <- c(invert.ci(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demTrustIndexDist, demTrustIndex)

demTrustIndexD <- demTrustIndex/sd(dataOneTwo$demTrustIndex, na.rm = T)

set.seed(932718)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demTrustIndexRescale) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demTrustIndex_hiInt <- estate(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive, prob = probsFourFive)

demTrustIndexOuts_hiInt <- genouts(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive)

demTrustIndexDist_hiInt <- gendist(demTrustIndexOuts_hiInt, perms = perms, prob = probsFourFive)

demTrustIndexCI_hiInt <- c(invert.ci(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demTrustIndexDist_hiInt, demTrustIndex_hiInt)

demTrustIndexD_hiInt <- demTrustIndex_hiInt/sd(dataOneTwo$demTrustIndex)


set.seed(968709)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demTrustIndexRescale) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demTrustIndex_loInt <- estate(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive, prob = probsFourFive)

demTrustIndexOuts_loInt <- genouts(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive)

demTrustIndexDist_loInt <- gendist(demTrustIndexOuts_loInt, perms = perms, prob = probsFourFive)

demTrustIndexCI_loInt <- c(invert.ci(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demTrustIndexRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demTrustIndexDist_loInt, demTrustIndex_loInt)

demTrustIndexD_loInt <- demTrustIndex_loInt/sd(dataOneTwo$demTrustIndex)


#Code to check for HTE by interest

set.seed(95325)

dataFourFive<- data[which(is.na(data$conditionFourFive) == F & is.na(data$demTrustIndexRescale) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataFourFive$block)

demTrustIndexHTE <- conduct_ri(
  model_1 = demTrustIndexRescale ~ conditionFourFive+ interest,
  model_2 = demTrustIndexRescale ~ conditionFourFive+ interest + conditionFourFive*interest,
  declaration = declaration,
  sharp_hypothesis = demTrustIndex,
  assignment = "conditionFourFive",
  data = dataFourFive,
  sims = N
)


set.seed(328896)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demThermNormRescale) == F & data$inattentive == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demThermNorm <- estate(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive, prob = probsFourFive)

demThermNormOuts <- genouts(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive)

demThermNormDist <- gendist(demThermNormOuts, perms = perms, prob = probsFourFive)

demThermNormCI <- c(invert.ci(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demThermNormDist, demThermNorm)

demThermNormD <- demThermNorm/sd(dataFourFive$demThermNormRescale)

set.seed(365425)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demThermNormRescale) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demThermNorm_hiInt <- estate(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive, prob = probsFourFive)

demThermNormOuts_hiInt <- genouts(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive)

demThermNormDist_hiInt <- gendist(demThermNormOuts_hiInt, perms = perms, prob = probsFourFive)

demThermNormCI_hiInt <- c(invert.ci(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demThermNormDist_hiInt, demThermNorm_hiInt)

demThermNormD_hiInt <- demThermNorm_hiInt/sd(dataOneTwo$demThermNormRescale)

set.seed(548635)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$demThermNormRescale) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demThermNorm_loInt <- estate(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive, prob = probsFourFive)

demThermNormOuts_loInt <- genouts(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive)

demThermNormDist_loInt <- gendist(demThermNormOuts_loInt, perms = perms, prob = probsFourFive)

demThermNormCI_loInt <- c(invert.ci(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$demThermNormRescale, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demThermNormDist_loInt, demThermNorm_loInt)

demThermNormD_loInt <- demThermNorm_loInt/sd(dataOneTwo$demThermNorm)

#Code to check for HTE by interest

set.seed(683457)

dataFourFive<- data[which(is.na(data$conditionFourFive) == F & is.na(data$demThermNormRescale) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataFourFive$block)

demThermNormHTE <- conduct_ri(
  model_1 = demThermNormRescale ~ conditionFourFive+ interest,
  model_2 = demThermNormRescale ~ conditionFourFive+ interest + conditionFourFive*interest,
  declaration = declaration,
  sharp_hypothesis = demThermNorm,
  assignment = "conditionFourFive",
  data = dataFourFive,
  sims = N
)


#Now Dem Social Distance to Reps

set.seed(765421)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$socDistDemsIndex) == F & data$inattentive == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demSocDistIndex <- estate(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive, prob = probsFourFive)

demSocDistIndexOuts <- genouts(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive)

demSocDistIndexDist <- gendist(demSocDistIndexOuts, perms = perms, prob = probsFourFive)

demSocDistIndexCI <- c(invert.ci(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demSocDistIndexDist, demSocDistIndex)

demSocDistIndexD <- demSocDistIndex/sd(dataFourFive$socDistDemsIndex)

set.seed(969955)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$socDistDemsIndex) == F & data$inattentive == 0 & data$interest == 1),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demSocDistIndex_hiInt <- estate(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive, prob = probsFourFive)

demSocDistIndexOuts_hiInt <- genouts(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive)

demSocDistIndexDist_hiInt <- gendist(demSocDistIndexOuts_hiInt, perms = perms, prob = probsFourFive)

demSocDistIndexCI_hiInt <- c(invert.ci(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demSocDistIndexDist_hiInt, demSocDistIndex_hiInt)

demSocDistIndexD_hiInt <- demSocDistIndex_hiInt/sd(dataOneTwo$demSocDistIndex)


set.seed(824579)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$socDistDemsIndex) == F & data$inattentive == 0 & data$interest == 0),]

perms <- genperms(dataFourFive$conditionFourFive, blockvar = dataFourFive$block, maxiter = N)

probsFourFive <- genprobexact(dataFourFive$conditionFourFive, blockvar = dataFourFive$block)

demSocDistIndex_loInt <- estate(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive, prob = probsFourFive)

demSocDistIndexOuts_loInt <- genouts(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive)

demSocDistIndexDist_loInt <- gendist(demSocDistIndexOuts_loInt, perms = perms, prob = probsFourFive)

demSocDistIndexCI_loInt <- c(invert.ci(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .05), invert.ci(dataFourFive$socDistDemsIndex, dataFourFive$conditionFourFive, prob = probsFourFive, perms = perms, targetp = .95))

dispdist(demSocDistIndexDist_loInt, demSocDistIndex_loInt)

demSocDistIndexD_loInt <- demSocDistIndex_loInt/sd(dataOneTwo$demSocDistIndex)


#Code to check for HTE by interest

set.seed(995747)

dataFourFive <- data[which(is.na(data$conditionFourFive) == F & is.na(data$socDistDemsIndex) == F & data$inattentive == 0 & is.na(data$interest) == F),]

declaration <- declare_ra(blocks = dataFourFive$block)

demSocDistIndexHTE <- conduct_ri(
  model_1 = socDistDemsIndex ~ conditionFourFive+ interest,
  model_2 = socDistDemsIndex ~ conditionFourFive+ interest + conditionFourFive*interest,
  declaration = declaration,
  sharp_hypothesis = demSocDistIndex,
  assignment = "conditionFourFive",
  data = dataFourFive,
  sims = N
)


##Creating objects for plotting


setwd("C:/Users/cdmyers/Box/Current Projects/Negative Exemplars/Study 2 - Dasgupta and Greenwald Replication/Data/Figures/")

#Creating Figure 2, Panel 2

demIssueResults <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

demIssueResults[1,] <- c(-demIssueIndex, as.numeric(-demIssueIndexCI[2]), as.numeric(-demIssueIndexCI[1]))
demIssueResults[2,] <- c(-demIdeo, as.numeric(-demIdeoCI[2]), as.numeric(-demIdeoCI[1]))
demIssueResults[3,] <- c(-demTaxes, as.numeric(-demTaxesCI[2]), as.numeric(-demTaxesCI[1]))
demIssueResults[4,] <- c(-demImmig, as.numeric(-demImmigCI[2]), as.numeric(-demImmigCI[1]))
demIssueResults[5,] <- c(-demAbortion, as.numeric(-demAbortionCI[2]), as.numeric(-demAbortionCI[1]))

rownames(demIssueResults) <- c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")

demIssuePlot <- ggplot(demIssueResults, aes(factor(rownames(demIssueResults), levels = c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")), ate, ymin = lower.ci, ymax = upper.ci)) 
demIssuePlot <- demIssuePlot + theme(aspect.ratio = 1/2)
demIssuePlot <- demIssuePlot + geom_pointrange(size = .5, cex = 3) 
demIssuePlot <- demIssuePlot + geom_hline(yintercept = 0)
demIssuePlot <- demIssuePlot + ggtitle("Effect of Moderate Exemplars on Republican Perceptions of Democratic Ideology")
demIssuePlot <- demIssuePlot + theme(plot.title = element_text(size = 10, hjust = .5))
demIssuePlot <- demIssuePlot + xlab("Issue (90% Confidence Intervals)")
demIssuePlot <- demIssuePlot + theme(axis.title.x = element_text(size = 8))
demIssuePlot <- demIssuePlot + ylab("<- More Moderate | More Liberal ->")
demIssuePlot <- demIssuePlot + theme(axis.title.y = element_text(size = 8))
demIssuePlot <- demIssuePlot + ylim(-.15, .15)

demIssuePlot

ggsave("demIssuePlot.png", width = 6.5, height = 2.9, units = "in")

#Creating the same figure among high-interest respondents for Appendix B

demIssueResults_hiInt <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

demIssueResults_hiInt[1,] <- c(-demIssueIndex_hiInt, as.numeric(-demIssueIndexCI_hiInt[2]), as.numeric(-demIssueIndexCI_hiInt[1]))
demIssueResults_hiInt[2,] <- c(-demIdeo_hiInt, as.numeric(-demIdeoCI_hiInt[2]), as.numeric(-demIdeoCI_hiInt[1]))
demIssueResults_hiInt[3,] <- c(-demTaxes_hiInt, as.numeric(-demTaxesCI_hiInt[2]), as.numeric(-demTaxesCI_hiInt[1]))
demIssueResults_hiInt[4,] <- c(-demImmig_hiInt, as.numeric(-demImmigCI_hiInt[2]), as.numeric(-demImmigCI_hiInt[1]))
demIssueResults_hiInt[5,] <- c(-demAbortion_hiInt, as.numeric(-demAbortionCI_hiInt[2]), as.numeric(-demAbortionCI_hiInt[1]))

rownames(demIssueResults_hiInt) <- c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")

demIssuePlot_hiInt <- ggplot(demIssueResults_hiInt, aes(factor(rownames(demIssueResults), levels = c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")), ate, ymin = lower.ci, ymax = upper.ci)) 
demIssuePlot_hiInt <- demIssuePlot_hiInt + theme(aspect.ratio = 1/2)
demIssuePlot_hiInt <- demIssuePlot_hiInt + geom_pointrange(size = .5, cex = 3) 
demIssuePlot_hiInt <- demIssuePlot_hiInt + geom_hline(yintercept = 0)
demIssuePlot_hiInt <- demIssuePlot_hiInt + ggtitle("Effect of Moderate Exemplars on Republican Perceptions of Democratic Ideology/n(High-Interest Respondents)")
demIssuePlot_hiInt <- demIssuePlot_hiInt + theme(plot.title = element_text(size = 10, hjust = .5))
demIssuePlot_hiInt <- demIssuePlot_hiInt + xlab("Issue (90% Confidence Intervals)")
demIssuePlot_hiInt <- demIssuePlot_hiInt + theme(axis.title.x = element_text(size = 8))
demIssuePlot_hiInt <- demIssuePlot_hiInt + ylab("<- More Moderate | More Liberal ->")
demIssuePlot_hiInt <- demIssuePlot_hiInt + theme(axis.title.y = element_text(size = 8))
demIssuePlot_hiInt <- demIssuePlot_hiInt + ylim(-.15, .15)

demIssuePlot_hiInt

ggsave("demIssuePlot_hiInt.png", width = 6.5, height = 2.9, units = "in")

#Creating the same figure among low-interest respondents for Appendix B

demIssueResults_loInt <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

demIssueResults_loInt[1,] <- c(-demIssueIndex_loInt, as.numeric(-demIssueIndexCI_loInt[2]), as.numeric(-demIssueIndexCI_loInt[1]))
demIssueResults_loInt[2,] <- c(-demIdeo_loInt, as.numeric(-demIdeoCI_loInt[2]), as.numeric(-demIdeoCI_loInt[1]))
demIssueResults_loInt[3,] <- c(-demTaxes_loInt, as.numeric(-demTaxesCI_loInt[2]), as.numeric(-demTaxesCI_loInt[1]))
demIssueResults_loInt[4,] <- c(-demImmig_loInt, as.numeric(-demImmigCI_loInt[2]), as.numeric(-demImmigCI_loInt[1]))
demIssueResults_loInt[5,] <- c(-demAbortion_loInt, as.numeric(-demAbortionCI_loInt[2]), as.numeric(-demAbortionCI_loInt[1]))

rownames(demIssueResults_loInt) <- c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")

demIssuePlot_loInt <- ggplot(demIssueResults_loInt, aes(factor(rownames(demIssueResults), levels = c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")), ate, ymin = lower.ci, ymax = upper.ci)) 
demIssuePlot_loInt <- demIssuePlot_loInt + theme(aspect.ratio = 1/2)
demIssuePlot_loInt <- demIssuePlot_loInt + geom_pointrange(size = 1, cex = 3) 
demIssuePlot_loInt <- demIssuePlot_loInt + geom_hline(yintercept = 0)
demIssuePlot_loInt <- demIssuePlot_loInt + ggtitle("Effect of Moderate Exemplars on Republican Perceptions of Democratic Ideology/n(Low-Interest Respondents)")
demIssuePlot_loInt <- demIssuePlot_loInt + theme(plot.title = element_text(size = 10, hjust = .5))
demIssuePlot_loInt <- demIssuePlot_loInt + xlab("Issue (90% Confidence Intervals)")
demIssuePlot_loInt <- demIssuePlot_loInt + theme(axis.title.x = element_text(size = 8))
demIssuePlot_loInt <- demIssuePlot_loInt + ylab("<- More Moderate | More Liberal ->")
demIssuePlot_loInt <- demIssuePlot_loInt + theme(axis.title.y = element_text(size = 8))
demIssuePlot_loInt <- demIssuePlot_loInt + ylim(-.15, .15)

demIssuePlot_loInt

ggsave("demIssuePlot_loInt.png", width = 6.5, height = 2.9, units = "in")

#Creating Figure 2, Panel 3

repIssueResults <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

repIssueResults[1,] <- c(repIssueIndex, as.numeric(repIssueIndexCI[2]), as.numeric(repIssueIndexCI[1]))
repIssueResults[2,] <- c(repIdeo, as.numeric(repIdeoCI[2]), as.numeric(repIdeoCI[1]))
repIssueResults[3,] <- c(repTaxes, as.numeric(repTaxesCI[2]), as.numeric(repTaxesCI[1]))
repIssueResults[4,] <- c(repImmig, as.numeric(repImmigCI[2]), as.numeric(repImmigCI[1]))
repIssueResults[5,] <- c(repAbortion, as.numeric(repAbortionCI[2]), as.numeric(repAbortionCI[1]))

rownames(repIssueResults) <- c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")

repIssuePlot <- ggplot(repIssueResults, aes(factor(rownames(repIssueResults), levels = c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")), ate, ymin = lower.ci, ymax = upper.ci)) 
repIssuePlot <- repIssuePlot + theme(aspect.ratio = 1/2)
repIssuePlot <- repIssuePlot + geom_pointrange(size = .5, cex = 3) 
repIssuePlot <- repIssuePlot + geom_hline(yintercept = 0)
repIssuePlot <- repIssuePlot + ggtitle("Effect of Moderate Exemplars on Democratic Perceptions of Republican Ideology")
repIssuePlot <- repIssuePlot + theme(plot.title = element_text(size = 10, hjust = .5))
repIssuePlot <- repIssuePlot + xlab("Issue (90% Confidence Intervals)")
repIssuePlot <- repIssuePlot + theme(axis.title.x = element_text(size = 8))
repIssuePlot <- repIssuePlot + ylab(" <- More Moderate | More Conservative ->")
repIssuePlot <- repIssuePlot + theme(axis.title.y = element_text(size = 8))
repIssuePlot <- repIssuePlot + ylim(-.15, .15)

repIssuePlot

ggsave("repIssuePlot.png", width = 6.5, height = 2.9, units = "in")

#Creating the same figure among high-interest respondents for Appendix B

repIssueResults_hiInt <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

repIssueResults_hiInt[1,] <- c(repIssueIndex_hiInt, as.numeric(repIssueIndexCI_hiInt[2]), as.numeric(repIssueIndexCI_hiInt[2]))
repIssueResults_hiInt[2,] <- c(repIdeo_hiInt, as.numeric(repIdeoCI_hiInt[2]), as.numeric(repIdeoCI_hiInt[2]))
repIssueResults_hiInt[3,] <- c(repTaxes_hiInt, as.numeric(repTaxesCI_hiInt[2]), as.numeric(repTaxesCI_hiInt[2]))
repIssueResults_hiInt[4,] <- c(repImmig_hiInt, as.numeric(repImmigCI_hiInt[2]), as.numeric(repImmigCI_hiInt[2]))
repIssueResults_hiInt[5,] <- c(repAbortion_hiInt, as.numeric(repAbortionCI_hiInt[2]), as.numeric(repAbortionCI_hiInt[2]))

rownames(repIssueResults_hiInt) <- c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")

repIssuePlot_hiInt <- ggplot(repIssueResults_hiInt, aes(factor(rownames(repIssueResults), levels = c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")), ate, ymin = lower.ci, ymax = upper.ci)) 
repIssuePlot_hiInt <- repIssuePlot_hiInt + theme(aspect.ratio = 1/2)
repIssuePlot_hiInt <- repIssuePlot_hiInt + geom_pointrange(size = .5, cex = 3) 
repIssuePlot_hiInt <- repIssuePlot_hiInt + geom_hline(yintercept = 0)
repIssuePlot_hiInt <- repIssuePlot_hiInt + ggtitle("Effect of Moderate Exemplars on Democratic Perceptions of Republican Ideology/n(High-Interest Respondents)")
repIssuePlot_hiInt <- repIssuePlot_hiInt + theme(plot.title = element_text(size = 10, hjust = .5))
repIssuePlot_hiInt <- repIssuePlot_hiInt + xlab("Issue (90% Confidence Intervals)")
repIssuePlot_hiInt <- repIssuePlot_hiInt + theme(axis.title.x = element_text(size = 8))
repIssuePlot_hiInt <- repIssuePlot_hiInt + ylab(" <- More Moderate | More Conservative ->")
repIssuePlot_hiInt <- repIssuePlot_hiInt + theme(axis.title.y = element_text(size = 8))
repIssuePlot_hiInt <- repIssuePlot_hiInt + ylim(-.15, .15)

repIssuePlot_hiInt

ggsave("repIssuePlot_hiInt.png", width = 6.5, height = 2.9, units = "in")

#Creating the same figure among low-interest respondents for Appendix B

repIssueResults_loInt <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

repIssueResults_loInt[1,] <- c(repIssueIndex_loInt, as.numeric(repIssueIndexCI_loInt[2]), as.numeric(repIssueIndexCI_loInt[2]))
repIssueResults_loInt[2,] <- c(repIdeo_loInt, as.numeric(repIdeoCI_loInt[2]), as.numeric(repIdeoCI_loInt[2]))
repIssueResults_loInt[3,] <- c(repTaxes_loInt, as.numeric(repTaxesCI_loInt[2]), as.numeric(repTaxesCI_loInt[2]))
repIssueResults_loInt[4,] <- c(repImmig_loInt, as.numeric(repImmigCI_loInt[2]), as.numeric(repImmigCI_loInt[2]))
repIssueResults_loInt[5,] <- c(repAbortion_loInt, as.numeric(repAbortionCI_loInt[2]), as.numeric(repAbortionCI_loInt[2]))

rownames(repIssueResults_loInt) <- c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")

repIssuePlot_loInt <- ggplot(repIssueResults_loInt, aes(factor(rownames(repIssueResults), levels = c("Issue Index", "Ideology", "Taxes", "Immigration", "Abortion")), ate, ymin = lower.ci, ymax = upper.ci)) 
repIssuePlot_loInt <- repIssuePlot_loInt + theme(aspect.ratio = 1/2)
repIssuePlot_loInt <- repIssuePlot_loInt + geom_pointrange(size = .5, cex = 3) 
repIssuePlot_loInt <- repIssuePlot_loInt + geom_hline(yintercept = 0)
repIssuePlot_loInt <- repIssuePlot_loInt + ggtitle("Effect of Moderate Exemplars on Democratic Perceptions of Republican Ideology/n(Low-Interest Respondents)")
repIssuePlot_loInt <- repIssuePlot_loInt + theme(plot.title = element_text(size = 10, hjust = .5))
repIssuePlot_loInt <- repIssuePlot_loInt + xlab("Issue (90% Confidence Intervals)")
repIssuePlot_loInt <- repIssuePlot_loInt + theme(axis.title.x = element_text(size = 8))
repIssuePlot_loInt <- repIssuePlot_loInt + ylab(" <- More Moderate | More Conservative ->")
repIssuePlot_loInt <- repIssuePlot_loInt + theme(axis.title.y = element_text(size = 8))
repIssuePlot_loInt <- repIssuePlot_loInt + ylim(-.15, .15)

repIssuePlot_loInt

ggsave("repIssuePlot_loInt.png", width = 6.5, height = 2.9, units = "in")

#Creating Figure 3, Panel 2

demAffectResults <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

demAffectResults[1,] <- c(demAffectIndex, as.numeric(demAffectIndexCI[1]), as.numeric(demAffectIndexCI[2]))
demAffectResults[2,] <- c(demSocDistIndex, as.numeric(demSocDistIndexCI[1]), as.numeric(demSocDistIndexCI[2]))
demAffectResults[3,] <- c(demTrustIndex, as.numeric(demTrustIndexCI[1]), as.numeric(demTrustIndexCI[2]))
demAffectResults[4,] <- c(demThermNorm, as.numeric(demThermNormCI[1]), as.numeric(demThermNormCI[2]))

rownames(demAffectResults) <- c("Affect Index", "Social Distance", "Trust", "Feeling Therm")

demAffectPlot <- ggplot(demAffectResults, aes(factor(rownames(demAffectResults), levels = c("Affect Index", "Trust", "Feeling Therm", "Social Distance")), ate, ymin = lower.ci, ymax = upper.ci)) 
demAffectPlot <- demAffectPlot + theme(aspect.ratio = 1/2)
demAffectPlot <- demAffectPlot + geom_pointrange(size = .5, cex = 3) 
demAffectPlot <- demAffectPlot + geom_hline(yintercept = 0)
demAffectPlot <- demAffectPlot + ggtitle("Effect of Moderate Exemplars on Republican Affect Towards Dems")
demAffectPlot <- demAffectPlot + theme(plot.title = element_text(size = 10, hjust = .5)) 
demAffectPlot <- demAffectPlot + xlab("Affect Measure (90% Confidence Intervals)")
demAffectPlot <- demAffectPlot + theme(axis.title.x = element_text(size = 8))
demAffectPlot <- demAffectPlot + ylab(NULL)
demAffectPlot <- demAffectPlot + ylim(-.1, .1)

demAffectPlot

ggsave("demAffectPlot.png", width = 6.5, height = 2.9, units = "in")

#Creating the same figure among high-interest respondents for Appendix B

demAffectResults_hiInt <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

demAffectResults_hiInt[1,] <- c(demAffectIndex_hiInt, as.numeric(demAffectIndexCI_hiInt[1]), as.numeric(demAffectIndexCI_hiInt[2]))
demAffectResults_hiInt[2,] <- c(demSocDistIndex_hiInt, as.numeric(demSocDistIndexCI_hiInt[1]), as.numeric(demSocDistIndexCI_hiInt[2]))
demAffectResults_hiInt[3,] <- c(demTrustIndex_hiInt, as.numeric(demTrustIndexCI_hiInt[1]), min(as.numeric(demTrustIndexCI_hiInt[2]), .1))
demAffectResults_hiInt[4,] <- c(demThermNorm_hiInt, as.numeric(demThermNormCI_hiInt[1]), as.numeric(demThermNormCI_hiInt[2]))

rownames(demAffectResults_hiInt) <- c("Affect Index", "Social Distance", "Trust", "Feeling Therm")

demAffectPlot_hiInt <- ggplot(demAffectResults_hiInt, aes(factor(rownames(demAffectResults_hiInt), levels = c("Affect Index", "Trust", "Feeling Therm", "Social Distance")), ate, ymin = lower.ci, ymax = upper.ci)) 
demAffectPlot_hiInt <- demAffectPlot_hiInt + theme(aspect.ratio = 1/2)
demAffectPlot_hiInt <- demAffectPlot_hiInt + geom_pointrange(size = .5, cex = 3) 
demAffectPlot_hiInt <- demAffectPlot_hiInt + geom_hline(yintercept = 0)
demAffectPlot_hiInt <- demAffectPlot_hiInt + ggtitle("Effect of Moderate Exemplars on Republican Affect Towards Dems/n(High-Interest Respondents)")
demAffectPlot_hiInt <- demAffectPlot_hiInt + theme(plot.title = element_text(size = 10, hjust = .5)) 
demAffectPlot_hiInt <- demAffectPlot_hiInt + xlab("Affect Measure (90% Confidence Intervals)")
demAffectPlot_hiInt <- demAffectPlot_hiInt + theme(axis.title.x = element_text(size = 8))
demAffectPlot_hiInt <- demAffectPlot_hiInt + ylab(NULL)
demAffectPlot_hiInt <- demAffectPlot_hiInt + ylim(-.1, .1)

demAffectPlot_hiInt

ggsave("demAffectPlot_hiInt.png", width = 6.5, height = 2.9, units = "in")

#Creating the same figure among low-interest respondents for Appendix B

demAffectResults_loInt <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

demAffectResults_loInt[1,] <- c(demAffectIndex_loInt, as.numeric(demAffectIndexCI_loInt[1]), as.numeric(demAffectIndexCI_loInt[2]))
demAffectResults_loInt[2,] <- c(demSocDistIndex_loInt, as.numeric(demSocDistIndexCI_loInt[1]), as.numeric(demSocDistIndexCI_loInt[2]))
demAffectResults_loInt[3,] <- c(demTrustIndex_loInt, as.numeric(demTrustIndexCI_loInt[1]), as.numeric(demTrustIndexCI_loInt[2]))
demAffectResults_loInt[4,] <- c(demThermNorm_loInt, as.numeric(demThermNormCI_loInt[1]), as.numeric(demThermNormCI_loInt[2]))


rownames(demAffectResults_loInt) <- c("Affect Index", "Social Distance", "Trust", "Feeling Therm")

demAffectPlot_loInt <- ggplot(demAffectResults_loInt, aes(factor(rownames(demAffectResults_loInt), levels = c("Affect Index", "Trust", "Feeling Therm", "Social Distance")), ate, ymin = lower.ci, ymax = upper.ci)) 
demAffectPlot_loInt <- demAffectPlot_loInt + theme(aspect.ratio = 1/2)
demAffectPlot_loInt <- demAffectPlot_loInt + geom_pointrange(size = .5, cex = 3) 
demAffectPlot_loInt <- demAffectPlot_loInt + geom_hline(yintercept = 0)
demAffectPlot_loInt <- demAffectPlot_loInt + ggtitle("Effect of Moderate Exemplars on Republican Affect Towards Dems/n(Low-Interest Respondents)")
demAffectPlot_loInt <- demAffectPlot_loInt + theme(plot.title = element_text(size = 10, hjust = .5)) 
demAffectPlot_loInt <- demAffectPlot_loInt + xlab("Affect Measure (95% Confidence Intervals)")
demAffectPlot_loInt <- demAffectPlot_loInt + theme(axis.title.x = element_text(size = 8))
demAffectPlot_loInt <- demAffectPlot_loInt + ylab(NULL)
demAffectPlot_loInt <- demAffectPlot_loInt + ylim(-.1, .1)

demAffectPlot_loInt

ggsave("demAffectPlot_loInt.png", width = 6.5, height = 2.9, units = "in")

#Creating Figure 2, Panel 3

repAffectResults <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

repAffectResults[1,] <- c(repAffectIndex, as.numeric(repAffectIndexCI[1]), as.numeric(repAffectIndexCI[2]))
repAffectResults[2,] <- c(repSocDistIndex, as.numeric(repSocDistIndexCI[1]), as.numeric(repSocDistIndexCI[2]))
repAffectResults[3,] <- c(repTrustIndex, as.numeric(repTrustIndexCI[1]), as.numeric(repTrustIndexCI[2]))
repAffectResults[4,] <- c(repThermNorm, as.numeric(repThermNormCI[1]), as.numeric(repThermNormCI[2]))

rownames(repAffectResults) <- c("Affect Index", "Social Distance", "Trust", "Feeling Therm")

repAffectPlot <- ggplot(repAffectResults, aes(factor(rownames(repAffectResults), levels = c("Affect Index", "Trust", "Feeling Therm", "Social Distance")), ate, ymin = lower.ci, ymax = upper.ci)) 
repAffectPlot <- repAffectPlot + theme(aspect.ratio = 1/2)
repAffectPlot <- repAffectPlot + geom_pointrange(size = .5, cex = 3) 
repAffectPlot <- repAffectPlot + geom_hline(yintercept = 0)
repAffectPlot <- repAffectPlot + ggtitle("Effect of Moderate Exemplars on Democratic Affect Towards Reps")
repAffectPlot <- repAffectPlot + theme(plot.title = element_text(size = 10, hjust = .5)) 
repAffectPlot <- repAffectPlot + xlab("Affect Measure (90% Confidence Intervals)")
repAffectPlot <- repAffectPlot + theme(axis.title.x = element_text(size = 8))
repAffectPlot <- repAffectPlot + ylab(NULL)
repAffectPlot <- repAffectPlot + ylim(-.1, .1)

repAffectPlot

ggsave("repAffectPlot.png", width = 6.5, height = 2.9, units = "in")

#Creating the same figure among high-interest respondents for Appendix B

repAffectResults_hiInt <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

repAffectResults_hiInt[1,] <- c(repAffectIndex_hiInt, as.numeric(repAffectIndexCI_hiInt[1]), as.numeric(repAffectIndexCI_hiInt[2]))
repAffectResults_hiInt[2,] <- c(repSocDistIndex_hiInt, as.numeric(repSocDistIndexCI_hiInt[1]), as.numeric(repSocDistIndexCI_hiInt[2]))
repAffectResults_hiInt[3,] <- c(repTrustIndex_hiInt, as.numeric(repTrustIndexCI_hiInt[1]), as.numeric(repTrustIndexCI_hiInt[2]))
repAffectResults_hiInt[4,] <- c(repThermNorm_hiInt, as.numeric(repThermNormCI_hiInt[1]), as.numeric(repThermNormCI_hiInt[2]))

rownames(repAffectResults_hiInt) <- c("Affect Index", "Social Distance", "Trust", "Feeling Therm")

repAffectPlot_hiInt <- ggplot(repAffectResults_hiInt, aes(factor(rownames(repAffectResults_hiInt), levels = c("Affect Index", "Trust", "Feeling Therm", "Social Distance")), ate, ymin = lower.ci, ymax = upper.ci)) 
repAffectPlot_hiInt <- repAffectPlot_hiInt + theme(aspect.ratio = 1/2)
repAffectPlot_hiInt <- repAffectPlot_hiInt + geom_pointrange(size = .5, cex = 3) 
repAffectPlot_hiInt <- repAffectPlot_hiInt + geom_hline(yintercept = 0)
repAffectPlot_hiInt <- repAffectPlot_hiInt + ggtitle("Effect of Moderate Exemplars on Democratic Affect Towards Reps/n(High-Interest Respondents)")
repAffectPlot_hiInt <- repAffectPlot_hiInt + theme(plot.title = element_text(size = 10, hjust = .5)) 
repAffectPlot_hiInt <- repAffectPlot_hiInt + xlab("Affect Measure (95% Confidence Intervals)")
repAffectPlot_hiInt <- repAffectPlot_hiInt + theme(axis.title.x = element_text(size = 8))
repAffectPlot_hiInt <- repAffectPlot_hiInt + ylab(NULL)
repAffectPlot_hiInt <- repAffectPlot_hiInt + ylim(-.1, .1)

repAffectPlot_hiInt

ggsave("repAffectPlot_hiInt.png", width = 6.5, height = 2.9, units = "in")

#Creating the same figure among low-interest respondents for Appendix B

repAffectResults_loInt <- data.frame(ate = numeric(), lower.ci = numeric(), upper.ci = numeric())

repAffectResults_loInt[1,] <- c(repAffectIndex_loInt, as.numeric(repAffectIndexCI_loInt[1]), as.numeric(repAffectIndexCI_loInt[2]))
repAffectResults_loInt[2,] <- c(repSocDistIndex_loInt, as.numeric(repSocDistIndexCI_loInt[1]), as.numeric(repSocDistIndexCI_loInt[2]))
repAffectResults_loInt[3,] <- c(repTrustIndex_loInt, as.numeric(repTrustIndexCI_loInt[1]), as.numeric(repTrustIndexCI_loInt[2]))
repAffectResults_loInt[4,] <- c(repThermNorm_loInt, as.numeric(repThermNormCI_loInt[1]), as.numeric(repThermNormCI_loInt[2]))


rownames(repAffectResults_loInt) <- c("Affect Index", "Social Distance", "Trust", "Feeling Therm")

repAffectPlot_loInt <- ggplot(repAffectResults_loInt, aes(factor(rownames(repAffectResults_loInt), levels = c("Affect Index", "Trust", "Feeling Therm", "Social Distance")), ate, ymin = lower.ci, ymax = upper.ci)) 
repAffectPlot_loInt <- repAffectPlot_loInt + theme(aspect.ratio = 1/2)
repAffectPlot_loInt <- repAffectPlot_loInt + geom_pointrange(size = .5, cex = 3) 
repAffectPlot_loInt <- repAffectPlot_loInt + geom_hline(yintercept = 0)
repAffectPlot_loInt <- repAffectPlot_loInt + ggtitle("Effect of Moderate Exemplars on Democratic Affect Towards Reps/n(Low-Interest Respondents)")
repAffectPlot_loInt <- repAffectPlot_loInt + theme(plot.title = element_text(size = 10, hjust = .5)) 
repAffectPlot_loInt <- repAffectPlot_loInt + xlab("Affect Measure (95% Confidence Intervals)")
repAffectPlot_loInt <- repAffectPlot_loInt + theme(axis.title.x = element_text(size = 8))
repAffectPlot_loInt <- repAffectPlot_loInt + ylab(NULL)
repAffectPlot_loInt <- repAffectPlot_loInt + ylim(-.1, .1)

repAffectPlot_loInt

ggsave("repAffectPlot_loInt.png", width = 6.5, height = 2.9, units = "in")
